<?php
class cls_control_search extends cls_control_base
{
	function keywords_search()
	{
		$search_serve=cls_serve_base::get_instance($this->name);
		$productdetail_serve = cls_serve_base::get_instance('productdetail');	
		$query_type=$_REQUEST['query_type'];
		$query=$_REQUEST['query'];
		$sort_name='id';
		$sort_order='asc';
		$search_re=$search_serve->keywords_search($query_type,$query,$sort_name,$sort_order);
		for($i=0;!empty($search_re[$i]);$i++)
		{
			$current_price=$productdetail_serve->get_current_price($search_re[$i]["ID"]); //加上现价
			$discount_info=$productdetail_serve->get_product_discount($search_re[$i]["ID"]);
			$search_re[$i]["current_price"]=$current_price;
			$search_re[$i]["discount_type"]=$discount_info["Type"];
			
		}
		echo json_encode($search_re);
	}
	
	function discount_info()
	{
		$search_serve=cls_serve_base::get_instance($this->name);
		$discount_id=$_REQUEST['discount_id'];
		$discount_info=$search_serve->discount_info($discount_id);
		echo json_encode($discount_info);
	}
	
	function discount_search()
	{
		$search_serve=cls_serve_base::get_instance($this->name);
		$productdetail_serve = cls_serve_base::get_instance('productdetail');
		$discount_id=$_REQUEST['discount_id'];
		$sort_name='p.id';
		$sort_order='asc';
		$search_re=$search_serve->discount_search($discount_id,$sort_name,$sort_order);
		for($i=0;!empty($search_re[$i]);$i++)
		{
			$current_price=$productdetail_serve->get_current_price($search_re[$i]["ID"]);
			$search_re[$i]["current_price"]=$productdetail_serve->get_current_price($search_re[$i]["ID"]);
			$search_re[$i]["saved_value"]=sprintf("%.2f",$productdetail_serve->get_saved_value($search_re[$i]["ID"]));
			$discount_info=$productdetail_serve->get_product_discount($search_re[$i]["ID"]);
			$search_re[$i]["discount_type"]=$discount_info["Type"];
		}
		
		echo json_encode($search_re);
	}
	
	function available_discount()
	{
		$search_serve=cls_serve_base::get_instance($this->name);
		$discount_info=$search_serve->available_discount();
		echo json_encode($discount_info);
	}
	

	
}